package fun.chutianshu.eescore_02_springbootMVC.controller;

import fun.chutianshu.eescore_02_springbootMVC.dao.StudentDao;
import fun.chutianshu.eescore_02_springbootMVC.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
public class HomeController {
    @Autowired
    StudentDao studentDao;

    @GetMapping("/")
    public String index(ModelMap map) {
        map.addAttribute("msg1", "Hello World");
        return "index";
    }

    @GetMapping("/stu_list")
    public String stuList(Model model) {
        List<Student> studentList = new ArrayList<Student>();
        studentList = studentDao.getAllStudents();
        System.out.println(studentList.get(0).toString());
        model.addAttribute("stuList",studentList);
        return "stu_list";
    }

}
